package com.gitee.huxing.course.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsMessagingTemplate;

import javax.jms.Destination;
import javax.jms.Queue;
import javax.jms.Topic;

/**
 * @Description: 消息发布者
 * @ProjectName: JavaCourse
 * @Package: com.gitee.huxing.course.controller
 * @ClassName: ProducerController
 * @Author: huxing
 * @DateTime: 2021-10-29 1:09 下午
 */
public class ProducerController {

    @Autowired
    JmsMessagingTemplate messagingTemplate;

    @Autowired
    private Queue queue;

    @Autowired
    private Topic topic;

    public void sendQueue(String message){
        this.sendMessage(this.queue, message);
    }

    public void sendTopic(String message){
        this.sendMessage(this.topic, message);
    }

    private void sendMessage(Destination destination, final String message){
        messagingTemplate.convertAndSend(destination, message);
    }
}
